package org.domain.sigerec.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cascade;

@Entity
public class Cliente implements Serializable {

	private static final long serialVersionUID = 701597969956282962L;
	private Long id;
	private String nome;
	private Date dataNascimento;
	private List<Reserva> reservas;
	private List<Telefone> telefones;
	private List<Cartao> cartoes;
	private Endereco endereco = new Endereco();

	public Cliente() {

	}

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	@Temporal(TemporalType.DATE)
	public Date getDataNascimento() {
		return dataNascimento;
	}

	public void setDataNascimento(Date dataNascimento) {
		this.dataNascimento = dataNascimento;
	}

	public void setReservas(List<Reserva> reservas) {
		this.reservas = reservas;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "RESERVA_CLIENTE", joinColumns = { @JoinColumn(name = "reserva_id") }, inverseJoinColumns = { @JoinColumn(name = "cliente_id") })
	public List<Reserva> getReservas() {
		return reservas;
	}

	public void setTelefones(List<Telefone> telefones) {
		this.telefones = telefones;
	}

	@OneToMany(cascade = CascadeType.ALL)
	@Cascade(value = { org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	public List<Telefone> getTelefones() {
		return telefones;
	}

	public void setCartao(List<Cartao> cartao) {
		this.cartoes = cartao;
	}

	@OneToMany(mappedBy = "cliente")
	@JoinColumn(name = "cartao_id")
	public List<Cartao> getCartao() {
		return cartoes;
	}

	public void setEndereco(Endereco endereco) {
		this.endereco = endereco;
	}

	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "endereco_id")
	public Endereco getEndereco() {
		return endereco;
	}

}
